# Contributor: TBK <alpine@jjtc.eu>
# Maintainer: lauren n. liberda <lauren@selfisekai.rocks>
pkgname=gn
pkgver=0_git20231023
pkgrel=0
_commit=e4702d7409069c4f12d45ea7b7f0890717ca3f4b
pkgdesc="Meta-build system that generates build files for Ninja"
arch="all"
url="https://gn.googlesource.com/gn"
license="BSD-3-Clause"
depends="samurai"
makedepends="python3 zstd"
# gitiles has no clones
source="https://s3.sakamoto.pl/lnl-aports-snapshots/gn-$_commit.tar.zst
	lfs64.patch
	"
builddir="$srcdir/gn"

_distbucket="sakamoto/lnl-aports-snapshots/"
snapshot() {
	clean
	deps
	mkdir -p "$srcdir" && cd "$srcdir"
	git clone https://gn.googlesource.com/gn
	(
		cd gn
		git checkout -q $_commit
		python3 ./build/gen.py
	)
	rm -rf gn/.git
	tar cf gn-$_commit.tar gn
	zstd --auto-threads=logical --ultra --long -22 -T"${ZSTD_LIMIT:-0}" -vv gn-$_commit.tar \
		-o "$SRCDEST"/gn-$_commit.tar.zst
	mcli cp "$SRCDEST"/gn-$_commit.tar.zst "$_distbucket"
}

build() {
	unset CFLAGS # all sources C++ but passes both
	CXXFLAGS="$CXXFLAGS -flto=auto" \
	python3 ./build/gen.py \
		--no-last-commit-position \
		--no-static-libstdc++ \
		--no-strip \
		--allow-warnings
	ninja -C out
}

check() {
	./out/gn_unittests
}

package() {
	install -Dm755 out/gn "$pkgdir"/usr/bin/gn
}

sha512sums="
fadbcde562db64a0e0c397e4bc7674a2660e0caf6eebdc996810e7a70b7504f085431bfba8700afb6c5c67abb985cc272fd043474ca372c961852c39f50561bd  gn-e4702d7409069c4f12d45ea7b7f0890717ca3f4b.tar.zst
1f0268a380a4d6f67446c6c3fe5c898c7241dde2881a790b86cabd68836aefffa776d85e323088b093c839965f3a076fcaf12ecaf022b1731cdfdfc2015330da  lfs64.patch
"
